<template>
    <h2>注册页面</h2>
    <table>
        <tr>
            <td>用户名</td>
            <td>
                <input type="text" placeholder="请输入用户名" v-model="info.Mname">
            </td>
        </tr>
        <tr>
            <td>密码</td>
            <td>
                <input type="password" placeholder="请输入密码" v-model="info.Pwd">
            </td>
        </tr>
        <tr>
            <td colspan="2" style="text-align:center">
                <input type="button" value="注册" @click="addMember"/>
            </td>
        </tr>
    </table>

 </template>

<script setup lang="ts">
import {ref} from 'vue'
import axios from 'axios'

const info=ref({
    Mname:"",
    Pwd:""
})
const addMember=()=>{
   
    if(info.value.Mname=="")
    {
        alert('用户名不能为空');
        return;
    }
    var reg=/^[a-zA-Z0-9]+$/;//任意位+
    if(!reg.test(info.value.Mname))
    {
        alert('用户名只能是字母和数字组成的六位字符');
        return;
    }
    if(info.value.Pwd=="")
    {
        alert('密码不能为空');
        return;
    }
    if(info.value.Pwd.length<3)
    {
        alert('密码长度不能小于3');
        return;
    }

    //通过axios发送请求到WebAPI
    axios.post('https://localhost:7234/api/MemberContorller/MemberRegister',{
        Mname:info.value.Mname,
        Pwd:info.value.Pwd
    }
    )
    .then(res=>{//对象
        if(res.data>0)
        {
            alert('注册成功');
            console.log(res);
        }
        else
        {
            alert('注册失败');
        }
    })
    .catch(error=>{
        console.log(error);
    })
    



}


</script>